import request from '@/utils/request'
import { AxiosPromise } from 'axios'
import { ICompanyForm, ICompanyQuery, ICompanyItem } from './types'

/**
 * 获取分页列表
 *
 * @param params
 */
export function getList(params: ICompanyQuery): AxiosPromise<PageResult<ICompanyItem[]>> {
  return request({
    url: '/companys',
    params
  })
}

/**
 * 修改
 *
 * @param id
 * @param data
 */
export function updateCompany(data: ICompanyForm) {
  return request({
    url: `/companys/${data.id}`,
    method: 'put',
    data: data
  })
}

/**
 * 获取详情
 *
 * @param userId
 */
export function getCompanyInfo(id: number): AxiosPromise<ICompanyForm> {
  return request({
    url: `/companys/${id}`
  })
}

/**
 * 添加
 *
 * @param data
 */
export function addCompany(data: ICompanyForm) {
  return request({
    url: '/companys',
    method: 'post',
    data: data
  })
}

/**
 * 删除
 *
 * @param id
 */
export function deleteCompany(id: string | number) {
  return request({
    url: `/companys/${id}`,
    method: 'delete'
  })
}

/**
 * 切换企业启用禁用状态
 *
 * @param id
 */
export function toggleCompanyEnable(data: { id: number; state: number }) {
  return request({
    url: `/companys/${data.id}/${data.state}`,
    method: 'post'
  })
}
